package cn.getech.data.development.entity.permission;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 租户数据权限配置
 */
@Data
public class SysTenantDataPermission implements Serializable {
    private Integer id;

    /**
     * 租户id
     */
    private Integer tenantId;

    /**
     * 数据id
     */
    private Integer dataId;

    /**
     * 1 数据源 ，2 数据仓库表，3数据仓库表字段，4数据服务,5元数据管理,6 实时表 7 实时表字段
     */
    private Integer dataType;

    /**
     * 查询权限 1 拥有,0 未拥有
     */
    private Integer query;

    /**
     * 数据写入权限 1 拥有 0 未拥有
     */
    private Integer write;

    /**
     * 修改权限 1 拥有,0 未拥有
     */
    private Integer update;

    /**
     * 删除权限 1 拥有,0 未拥有
     */
    private Integer delete;

    /**
     * 创建权限 1 拥有,0 未拥有
     */
    private Integer create;

    /**
     * 授权权限 1 拥有,0 未拥有
     */
    private Integer assign;

    /**
     * 导出权限 1 拥有,0 未拥有
     */
    private Integer export;

    /**
     * 加密权限 1 拥有,0 未拥有
     */
    private Integer decrypt;

    public void defaultValue(Integer tenantId, Integer dataId, Integer dataType) {
        this.tenantId = tenantId;
        this.dataId = dataId;
        this.dataType = dataType;
        this.query = 0;
        this.update = 0;
        this.delete = 0;
        this.create = 0;
        this.assign = 0;
        this.export = 0;
        this.decrypt = 0;
        this.write = 0;
    }

    public SysTenantDataPermission toPermission(SysTenantDataPermission sysTenantDataPermission) {
        SysTenantDataPermission permission = new SysTenantDataPermission();
        permission.setQuery(sysTenantDataPermission.getQuery());
        permission.setCreate(sysTenantDataPermission.getCreate());
        permission.setUpdate(sysTenantDataPermission.getUpdate());
        permission.setDelete(sysTenantDataPermission.getDelete());
        permission.setAssign(sysTenantDataPermission.getAssign());
        permission.setDecrypt(sysTenantDataPermission.getDecrypt());
        permission.setExport(sysTenantDataPermission.getExport());
        permission.setDataId(sysTenantDataPermission.getDataId());
        permission.setTenantId(sysTenantDataPermission.getTenantId());
        permission.setDataType(sysTenantDataPermission.getDataType());
        permission.setId(sysTenantDataPermission.getId());
        permission.setWrite(sysTenantDataPermission.getWrite());
        return permission;
    }

    /**
     * 前端需要一天临时唯一的id
     */
    @ApiModelProperty("前端需要一天临时唯一的id")
    private String uniqueId;

    public String getUniqueId() {
        return this.getDataId()+"_"+this.getDataType();
    }


    public void yesValue(Integer tenantId ,Integer dataId, Integer dataType) {
        this.tenantId = tenantId;
        this.dataId = dataId;
        this.dataType = dataType;
        this.query = 1;
        this.update = 1;
        this.delete = 1;
        this.create = 1;
        this.assign = 1;
        this.export = 1;
        this.decrypt = 1;
        this.write = 1;
    }
}